home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / C++ AppleLink Messages / CPlus.Dev$ 5⁄4⁄90 / 0116-Re Handling Construc-Apr90 < prev    next >
Encoding:
Text File  |  1990-05-04  |  1.6 KB  |  35 lines  |  [TEXT/GEOL]

  1. Item    7219558                         28-April-90        20:27PDT
  2.  
  3. From:   MIKE.VILOT                      ObjectWare, Michael Vilot,PRT
  4.  
  5. To:     D0532                           Aidea Systems, Don Park,PRT
  6.  
  7. cc:     CPLUS.DEV$                      C++ Interest List--Developers
  8.         CPLUS.APPLE$                    C++ Interest List--Apple Employees
  9.  
  10. Sub:    Re: Handling Constructor…
  11.  
  12. Well, I'll bypass the obvious questions regarding your need to use
  13. malloc/free over either new/delete or Mac Toolbox calls ...
  14.  
  15.     One of the nice aspects of having objects to work with is that they
  16. maintain state.  That is, they can ``remember'' has has (or has not)
  17. happened to them.  In your example, it is not necessary to require clients
  18. manually invoke a Validate function, since the semantics of it can be
  19. internal to the DoSomething function.
  20.     That is, the object can have an additional member to record whatever
  21. status you would like to maintain about the validity or integrity of
  22. the object.  The object's member functions would consult it before doing
  23. anything, and basically take no action if the object was not in a healthy
  24. state.
  25.     The case of allocating dynamic objects is more interesting.  Take a
  26. look at the header file ``new.h'' and the function set_new_handler.  By
  27. default, operator new returns NULL if it fails to retain the behavior of
  28. malloc().  However, it does this only if the function pointer _new_handler
  29. is NULL (the default).  You can use set_new_handler() to a function of
  30. your choosing.  That way, you will be notified if operator new ever fails.
  31.  
  32. Hope this helps,
  33.     Mike
  34.  
  35.